define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'agentsystem/agency/index',
                    add_url: 'agentsystem/agency/add',
                    edit_url: 'agentsystem/agency/edit',
                    del_url: 'agentsystem/agency/del',
                    multi_url: 'agentsystem/agency/multi',
                    table: 'y_agency',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'ID',
                sortName: 'ID',
                sortOrder: 'asc',
                search: false,
                columns: [
					[
						{checkbox: true},
						{field: 'RegisterTime', title: __('Registertime'), operate: 'RANGE', addclass: 'datetimerange'},
						{field: 'LoginName', title: __('Loginname')},
						{field: 'UserName', title: __('Username')},
						{field: 'LevelID', title: __('Levelid'), searchList: {'0':'超级', '1': '合伙人', '2': '区域合伙人', '3': '区域总代理', '4': '钻石代理', '5': '黄金代理'}},
						{field: 'ParentID', title: __('Parentid')},
						{field: 'TrueName', title: __('Truename')},
						{field: 'sex', title: __('Sex'), operate: false},
						{field: 'MobilePhone', title: __('Mobilephone')},
						{field: 'uid', title: __('Uid')},
						{field: 'nickname', title: __('Nickname')},
						{field: 'diamond', title: __('Diamond'), operate: '>=', placeholder: '大于等于'},   
						{field: 'money', title:'提现金额', operate: false},   
						{field: 'Address', title: __('Address'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
						{field: 'Status', title: __('Status'), formatter: Table.api.formatter.status,searchList: {'locked': __('locked'), 'normal': __('normal')}}
					]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});